def is_prime (n):
    for i in range (2, n):
        if n % i == 0:
            return False
    return True
n = input()
if len(n) != 4:
    print(0)
    exit()
number = [int(n[0]),int(n[1]),int(n[2]),int(n[3]),int(n), int(n[0: 2]), int(n[0:3]), int(n[1: 3]), int(n[1: 4]), int(n[2: 4])]
result = []
for i in number:
    if is_prime(i) == True:
        result.append(i)
if len(result) > 0:
    print(max(result))
else:
    print(0)

































































































































































































































































































































